---@class GT.ui.model.magic_effects 魔法效果模块
GT.ui.model.magic_effects = class()


---@class magic_effects_data
---@field text string 描述
---@field count number 层数


---@type table<UnitID,GT.ui.model.magic_effects[]>
magic_effects = OrderedTable()

---@type table<RoleID,UnitID> 玩家选择单位
select_unit = OrderedTable()
function GT.ui.model.magic_effects:ctor()
    self.ui = {}
    self.prefab = {}
    self.tick = {}

    self.prefab["魔法效果"] = GT.ui.prefab.obj({
        module = "e56f0881-4bea-4209-abfe-975c417ace2d",
        parent = "panel_2",

    })

    local p = self.prefab["魔法效果"]
    self.ui["self"] = p:child(GT.ui.control.image, "魔法效果背景")
    self.ui["self"].binding.show = false
    self.ui["self"]:enter(function(data, player, ui)
        self.ui["提示"].u[player.pid].binding.show = true
    end)
    self.ui["self"]:leave(function(data, player, ui)
        self.ui["提示"].u[player.pid].binding.show = false
    end)

    self.ui["进度"] = p:child(GT.ui.control.progress, "进度")
    self.ui["层数"] = p:child(GT.ui.control.label, "层数")
    self.ui["提示"] = p:child(GT.ui.control.scroll_view, "提示")
    self.ui["text"] = p:child(GT.ui.control.label, "提示.text")
end

---@param ut GT.unit
---@param data magic_effects_data
---@return GT.ui.model.magic_effects
function GT.ui.model.magic_effects.obj(ut, data)
    local p = ut:get_player()
    local u = new(GT.ui.model.magic_effects)
    if magic_effects[ut:api_get_id()] == nil then
        magic_effects[ut:api_get_id()] = {}
    end
    table.insert(magic_effects[ut:api_get_id()], u)
    u.ui["text"].binding.text = data.text
    u.ui["层数"].binding.text = data.count
    u.ui["进度"].binding.bind_attr = {
        cur = 100,
        max = 100,
    }
    return u
end

function GT.ui.model.magic_effects:del()
    self.prefab["魔法效果"]:del()
end

---@param p GT.player
function GT.ui.model.magic_effects:show(p)
    self.ui["self"].u[p.pid].binding.show = true
end

---@param p GT.player
function GT.ui.model.magic_effects:hide(p)
    self.ui["self"].u[p.pid].binding.show = false
end


